// pages/patient/index.js
const App = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    peopleList:[],
    type:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getPeople()

    this.setData({
      type:options.type?options.type:'0',
      k_name:options.name?options.name:'',
      goods_id:options.goods_id?options.goods_id:'',
      patient_id:options.patient_id?options.patient_id:'',
      patient_name:options.patient_name?options.patient_name:'',
      department_id:options.department_id?options.department_id:'',
      mail_address_id:options.mail_address_id?options.mail_address_id:'',
      address:options.address?options.address:'',
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },


  addBtn(){
    wx.redirectTo({
      url: '/pages/patient/add/index?type='+this.data.type+'&name='+this.data.k_name+'&goods_id='+this.data.goods_id+'&department_id='+this.data.department_id+'&mail_address_id='+this.data.mail_address_id+'&address='+this.data.address,
    })
  },
  getPeople(){
    let _this = this;
    App._get('patient/index', {
    }, result => {
      // 设置顶部导航栏栏
      _this.setData({
        peopleList:result.data.list
      });
    });
  },
  del(e){
    let _this = this;
    App._get('patient/delete', {
      id:e.currentTarget.dataset.id
    }, result => {
      // 设置顶部导航栏栏
      _this.getPeople()
    });
  },


  toForm(e){
    console.log(e)
    if(this.data.type=='0'){
      wx.redirectTo({
        url: '/pages/order_creted/index?patient_id='+e.currentTarget.dataset.id+'&patient_name='+e.currentTarget.dataset.name+'&name='+this.data.k_name+'&goods_id='+this.data.goods_id+'&department_id='+this.data.department_id+'&mail_address_id='+this.data.mail_address_id+'&address='+this.data.address,
      })
    }else if(this.data.type=='1'){
      wx.redirectTo({
        url: '/pages/order_form/index?patient_id='+e.currentTarget.dataset.id+'&patient_name='+e.currentTarget.dataset.name+'&name='+this.data.k_name+'&goods_id='+this.data.goods_id+'&department_id='+this.data.department_id+'&mail_address_id='+this.data.mail_address_id+'&address='+this.data.address,
      })
    }
    
  }
})